package cn.hchaojie.camp.week1.qa;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class Ex13MatrixSum {
	private static final double[][] MATRIX = {
		{1.5, 2, 3, 4},
		{2.3, 5, 8, 9},
		{3, 5.4, 7, 10}
	};
	
	private static final double[] RESULT = {6.8, 12.4, 18, 23};
	private static final double E = 0.001;

	@Test
	public void verify() {
		for (int i = 0; i < RESULT.length; i++) {
			double sum = sumColumn(MATRIX, i);
			assertTrue(Math.abs(sum - RESULT[i]) < E);
		}
	}
	
	public static double sumColumn(double[][] matrix, int column) {
		double sum = 0;
		for (int r = 0; r < matrix.length; r++) {
			sum += matrix[r][column];
		}
		return sum;
	}
}
